"""
@Project ：Python_Learning 
@File    ：58.最后一个单词的长度.py
@IDE     ：PyCharm 
@Author  ：zhupp
@Date    ：2024/10/17 14:04 
"""

class Solution:
    def lengthOfLastWord(self, s: str) -> int:
        # strip_s = s.strip(" ")
        # list_s = strip_s.split(" ")
        # print(list_s)
        # last_length = len(list_s[-1].strip(" "))
        # return last_length
        bool_word = False

        length_end = 0
        length_start = -1
        for i in range(len(s)-1, -1, -1):
            if s[i] != ' ' and not bool_word:
                length_end = i
                print("a ", length_end)
                bool_word = True
            if s[i] == ' ' and bool_word:
                length_start = i
                print("b ", length_start)
                break
        print(length_end, length_start)
        return length_end - length_start


s = Solution()
print(s.lengthOfLastWord("fly me  to the moon  "))

